from enum import Enum, unique

from .Block import BlockType
from .Buildings import BuildingType, get_building
from dataclasses import dataclass

from Utils import logger

"""
生物群系数据
"""

BiomeRegistry = {}  # 生物群落注册表


@unique
class BiomeType(Enum):
    Plains = 0
    PodzolPlains = 1
    SnowyPlain = 2


@dataclass
class Biome:  # 生物群落
    biome_type: BiomeType  # 生物群落类型
    name: str = ''  # 生物群落名称
    ids: int = 0  # 生物群落id
    grass_layer: BlockType = None  # 草层
    dirt_layer: BlockType = None  # 地层
    stone_layer: BlockType = None  # 石层
    building_type: BuildingType = None  # 建筑类型

    def __post_init__(self):
        self.name = self.biome_type.name
        self.ids = self.biome_type.value

        BiomeRegistry[self.biome_type.value] = self

    @staticmethod
    def get_biome_by_noise_value(noise_value) -> int:
        """按噪声值获取生物群系"""
        if 0.0 <= noise_value < 0.33333:
            return 0
        elif 0.33333 <= noise_value < 0.44444:
            return 1
        elif 0.44444 <= noise_value:
            return 2
        else:
            return 0


BiomeList = [
    Biome(BiomeType.Plains,
          grass_layer=BlockType.Grass,
          dirt_layer=BlockType.Dirt,
          stone_layer=BlockType.Stone,
          building_type=get_building(BuildingType.OAK_TREE)),
    Biome(BiomeType.PodzolPlains,
          grass_layer=BlockType.Podzol,
          dirt_layer=BlockType.Dirt,
          stone_layer=BlockType.Stone,
          building_type=get_building(BuildingType.DARK_RIP)),
    Biome(BiomeType.SnowyPlain,
          grass_layer=BlockType.SnowyGrass,
          dirt_layer=BlockType.Dirt,
          stone_layer=BlockType.Stone,
          building_type=get_building(BuildingType.BIRCH_TREE)),
]
logger.info(f'已加载{len(BiomeRegistry)}个群系')
